<template>
  <div>
    <span>登录状态与统计</span><br>
    <img src="" width="100" height="100" id="head"><br>
    <span>登录用户</span><br>
    用户名：<span>{{ loginUser.name }}</span><br>
    用户邮箱：<span>{{ loginUser.email }}</span>
    <table border="1" cellspacing="0" width="600">
      <thead>
      <tr>
        <th>频道名称</th>
        <th>频道描述</th>
        <th>主贴数量</th>
      </tr>
      </thead>
      <tbody v-for="c in channelList" :key="c.id">
      <tr>
        <td><a @click="selectChannel(c.id)">{{ c.name }}</a></td>
        <td>{{ c.description }}</td>
        <td>{{ c.themeNum }}</td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      loginUser: {},
      channelList: [],
    }
  },
  created() {
    this.findById(this.loginUser.id);
    this.findAllChannel();
  },
  methods: {
    findById(id) {
      axios.get("/project/user/findById", {params: {id}}).then(resp => {
        this.loginUser = resp.data;
      })
    },
    findAllChannel() {
      axios.get("/project/channel/findAll").then(resp => {
        this.channelList = resp.data;
      })
    },
    selectChannel(id) {
      axios.get("/project/channel/selectChannel", {params: {
          channelId:id
        }}).then(resp => {
        if (resp.data == "ok") {
          this.$router.push({name: "Theme", query: {id}});
        }
      })
    }
  }
}

</script>

<style scoped>

</style>